package org.telegram.bot.service.impl;

import com.ruoyi.common.utils.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.telegram.bot.domain.BotMessageTextCheck;
import org.telegram.bot.service.IBotGroupService;
import org.telegram.bot.service.IEditedMessageService;
import org.telegram.telegrambots.meta.api.objects.Update;

/**
 * @Author: wyx
 * @Date: 2023/6/13 21:13
 */
@Service
public class EditedMessageServiceImpl implements IEditedMessageService {
    
    @Resource
    private IBotGroupService groupService;
    
    @Override
    public void handle(Update update, Long chatId, String botId) {
        String text = update.getEditedMessage().getText();
        if(StringUtils.isNotEmpty(update.getEditedMessage().getCaption())){
            text += update.getEditedMessage().getCaption();
        }
        BotMessageTextCheck textCheck = new BotMessageTextCheck()
                .setChatId(chatId)
                .setChatType(update.getEditedMessage().getChat().getType())
                .setBotId(botId)
                .setUserId(update.getEditedMessage().getFrom().getId())
                .setMessageId(update.getEditedMessage().getMessageId())
                .setText(text)
                .setEntities(update.getEditedMessage().getEntities());
        if(update.getEditedMessage().getLinkPreviewOptions()!=null){
            textCheck.setLinkPreview(update.getEditedMessage().getLinkPreviewOptions().getUrlField());
        }
        groupService.messageTextCheck(textCheck);
    }
}
